------------------------------------------------------------------
-- 批量学习组件
-- 用法：
-- inst:AddComponent("multi_teacher")
-- inst.components.multi_teacher:SetRecipes({
--     "配方1的预制体代码",
--     "配方2的预制体代码",
--     "配方3的预制体代码",
--     "配方4的预制体代码",
-- })
------------------------------------------------------------------

local MultiTeacher = Class(function(self, inst)
    self.inst = inst
    self.recipes = {} -- 存储要教授的配方表
end)

------------------------------------------------------------------
-- 设置可教授的配方表
------------------------------------------------------------------
function MultiTeacher:SetRecipes(recipes)
    if type(recipes) == "table" then
        self.recipes = recipes
    else
        self.recipes = { recipes }
    end
end

------------------------------------------------------------------
-- 教授逻辑：遍历 self.recipes 执行解锁
------------------------------------------------------------------
function MultiTeacher:Teach(target)
    -- 防御：目标无builder组件直接跳出
    if target == nil or target.components.builder == nil then
        return false, "NOT_BUILDER"
    end

    local learned_any = false -- 是否学到至少一个
    local learned_list = {}   -- 记录成功解锁的配方

    for _, recipe in ipairs(self.recipes) do
        if not target.components.builder:KnowsRecipe(recipe, true)
            and target.components.builder:CanLearn(recipe) then
            target.components.builder:UnlockRecipe(recipe)
            learned_any = true
            table.insert(learned_list, recipe)

            -- 推送事件（保持与原蓝图一致）
            target:PushEvent("learnrecipe", { teacher = self.inst, recipe = recipe })
        end
    end

    -- 如果一本书所有配方都无法学习，则不销毁书本
    if learned_any then
        return true
    else
        return false, "ALL_KNOWN"
    end
end

------------------------------------------------------------------
return MultiTeacher
